#include <iterator>
#include <iostream>
#include <fstream>
#include <map>
#include <vector>
#include <string>
#include <cctype>
using namespace std;

string getNextToken(istream &in);
string getNextToken1(istream &in);

bool compare(int i, int j) {
	return i > j;
}

vector<string> stopwords() {

    vector<string> names;
    ifstream fin("stopwords.txt");
    string s1;
    string empty ="";
  //  cout<<22222;
    while((s1=getNextToken1(fin))!=empty )
           {
             //  cout<<s1;
            names.push_back (s1);
           }
    return names;
     }



string getNextToken(istream &in, ofstream &out)
{
    char c;
    string ans="";
    c=in.get();
    while(!isalpha(c) && !in.eof())//cleaning non letter charachters
    {
        out<<(char)c;
        c=in.get();
    }
    while(isalpha(c))
    {
        ans.push_back(tolower(c));
        c=in.get();
    }
    out<<(char)c;
    return ans;
}

string getNextToken1(istream &in)
{
    char c;
    string ans="";
    c=in.get();
    while(!isalpha(c) && !in.eof())//cleaning non letter charachters
    {

        c=in.get();
    }
    while(isalpha(c))
    {
        ans.push_back(tolower(c));
        c=in.get();
    }
    return ans;
}

int main(int argc, char * argv[])
{
  //  cout<<111111;
    vector<string> name;
    name=stopwords();
  //  cout<<111111;
    ifstream fin;
    fin.open(argv[1],ios::binary);
    ofstream fout;
    fout.open("stpwrds_output.txt", ios::binary);
    string s;
    bool flag;
    string empty ="";
    vector<string>::iterator iter;
    while((s=getNextToken(fin,fout))!=empty )
            { // cout<<s;
                flag=0;
                for(iter=name.begin(); iter != name.end(); iter++)
                {
                    if (*iter==s)
                    flag=1;
                }
                if (!flag)
                fout<<s;
            }

}
